﻿Public Class clsSach
    Public Shared Function DanhSachDS() As DataTable
        Return db.QueryTable("Select MaSach,TenSach,TenTL,TenNXB,NamXB,SoLuong,ViTri from Sach s inner join TheLoai t on s.MaTL=t.MaTL inner join NhaXuatBan n on s.MaNXB = n.MaNXB ")
    End Function

    Public Shared Function PhanLoaiNXB(ByVal MaNXB As String) As DataTable
        Return db.QueryTable("Select MaSach,TenSach,TenTL,TenNXB,NamXB,SoLuong,ViTri from NhaXuatBan n inner join Sach s on n.MaNXB=s.MaNXB inner join TheLoai t on t.MaTL = s.MaTL where n.MaNXB ='" & MaNXB & "'")
    End Function

    Public Shared Function PhanLoaiTL(ByVal MaTL As String) As DataTable
        Return db.QueryTable("Select MaSach,TenSach,TenTL,TenNXB,NamXB,SoLuong,ViTri from TheLoai t inner join Sach s on t.MaTL=s.MaTL inner join NhaXuatBan n on n.MaNXB = s.MaNXB where t.MaTL ='" & MaTL & "'")
    End Function
    Public Shared Function ThemS(ByVal MaSach As String, ByVal TenSach As String, ByVal MaTL As String, ByVal MaNXB As String, ByVal SoLuong As Integer, ByVal ViTri As String, ByVal NamXB As Integer) As Boolean
        Return db.Query("Insert into Sach values('" & MaSach & "','" & TenSach & "','" & ViTri & "'," & SoLuong & ",'" & MaTL & "','" & MaNXB & "'," & NamXB & ")")
    End Function
    Public Shared Function SuaS(ByVal MaSach As String, ByVal TenSach As String, ByVal MaTL As String, ByVal MaNXB As String, ByVal SoLuong As Integer, ByVal ViTri As String, ByVal NamXB As Integer) As Boolean
        Return db.Query("Update Sach set TenSach=N'" & TenSach & "',ViTri=N'" & ViTri & "',SoLuong=" & SoLuong & ",MaTL='" & MaTL & "',MaNXB='" & MaNXB & "',NamXB=" & NamXB & " where MaSach ='" & MaSach & "'")
    End Function
    Public Shared Function XoaS(ByVal MaSach As String) As Boolean
        Return db.Query("Delete Sach where MaSach ='" & MaSach & "'")
    End Function

    Public Shared Function TimKiem(ByVal TuKhoa As String) As DataTable
        Return db.QueryTable("Select MaSach,TenSach,ViTri,SoLuong,TenTL,TenNXB,NamXB from TheLoai t inner join Sach s on t.MaTL=s.MaTL inner join NhaXuatBan n on s.MaNXB=n.MaNXB where MaSach like '%" & TuKhoa & "%'or TenSach like N'%" & TuKhoa & "%'or ViTri like N'%" & TuKhoa & "%'or SoLuong like '%" & TuKhoa & "%' or TenTL like N'%" & TuKhoa & "%'or TenNXB like N'%" & TuKhoa & "%'or NamXB like '%" & TuKhoa & "%'")

    End Function
    Public Shared Function DanhSachTacGia() As DataTable

        Return db.QueryTable("Select TenTG,GhiChu from Sach_TacGia")
    End Function
End Class
